package com.ss.android.newmedia.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;

import com.bytedance.common.utility.ICustomToast;
import com.ss.android.common.app.AbsActivity;
import com.ss.android.j.ClickableBackgroundCompat;
import com.ss.android.newmedia.a.PopupToast;
import com.ss.android.newmedia.a.OverridePendingTransitionHelper;

public class BaseActivity extends AbsActivity implements ICustomToast {
    public static final String ACTIVITY_TRANS_TYPE = "activity_trans_type";
    public static final String OVERRIDE_ACTIVITY_TRANS = "delay_override_activity_trans";
    public int mActivityAnimType = 0;
    private int mCurTheme = -1;
    private PopupToast mCustomToast;
    public boolean mIsOverrideAnimation = false;
    private int mOriginTheme = -1;

    public void dismissCustomToast() {
        if (this.mCustomToast != null) {
            this.mCustomToast.dismiss();
        }
    }

    private void ensureCustomToast() {
        if (this.mCustomToast == null) {
            this.mCustomToast = new PopupToast(((Context) this));
        }
    }

    public void finish() {
        super.finish();
        if (!this.mIsOverrideAnimation) {
            OverridePendingTransitionHelper.overrideExitPendingTransition(this, this.mActivityAnimType);
        }
    }

    public int getOriginTheme() {
        return this.mOriginTheme;
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.mIsOverrideAnimation = this.getIntent().getBooleanExtra("delay_override_activity_trans", false);
        if (this.mActivityAnimType == 0) {
            this.mActivityAnimType = this.getIntent().getIntExtra("activity_trans_type", 0);
        }

        if (!this.mIsOverrideAnimation) {
            OverridePendingTransitionHelper.overrideEnterPendingTransition(this, this.mActivityAnimType);
        }
    }

    public void onDestroy() {
        super.onDestroy();
        if (this.mCustomToast != null) {
            this.mCustomToast.onDestroy();
        }
    }

    public void onResume() {
        super.onResume();
    }

    public void overridePendingTransition(int arg1, int arg2) {
    }

    @SuppressLint("ResourceType")
    public void setTheme(int resId) {
        if (!com.ss.android.j.c.isAboveLOLLIPOP()) {
            super.setTheme(resId);
        } else if (resId >= 0) {
            if (this.mOriginTheme == -1) {
                this.mOriginTheme = resId;
            }
            this.mCurTheme = ClickableBackgroundCompat.getTheme(resId);
            super.setTheme(this.mCurTheme);
        }
    }

    public void showCustomLongToast(int imageResId, String content) {
        if (this.isViewValid()) {
            this.ensureCustomToast();
            this.mCustomToast.showToast(imageResId, 0, content, 3500, 17);
        }
    }

    public void showCustomToast(int imageResId, String content) {
        if (this.isViewValid()) {
            this.ensureCustomToast();
            this.mCustomToast.showToast(imageResId, 0, content, 2000, 17);
        }
    }

    public void showCustomToast(int imageResId, String content, int duration, int gravity) {
        if (this.isViewValid()) {
            this.ensureCustomToast();
            this.mCustomToast.showToast(imageResId, 0, content, duration, gravity);
        }
    }

    public void showCustomToast(String content) {
        if (this.isViewValid()) {
            this.ensureCustomToast();
            this.mCustomToast.showToast(0, 0, content, 2000, 17);
        }
    }

    public void showCustomToast(String content, int duration, int gravity) {
        if (this.isViewValid()) {
            this.ensureCustomToast();
            this.mCustomToast.showToast(0, 0, content, duration, gravity);
        }
    }

    public void superOverridePendingTransition(int enterAnim, int exitAnim) {
        super.overridePendingTransition(enterAnim, exitAnim);
    }
}

